<template>
	<view>
		<view class="bg-white padding">
			<view class="rowsc margin-top">
				<view class="round rowsc align-center" style="background-color: #4CD964;width: 200rpx;height: 200rpx;">
					<view class="text-bold text-white" style="font-size: 50rpx;">
						<view class="text-center">
							<view class=""> {{errorsDataList.length}}</view>
							<view class="text-sm">
								全部错题
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="rowsc margin-top-xl">
				<view class="round text-bold" style="border: 1rpx solid #007AFF; color:#007AFF ;padding: 15rpx 30rpx;">
					查看全部错题
				</view>
			</view>
		</view>
		<view class="margin-top-sm bg-white padding">
			<view class="text-bold solid-bottom padding-bottom-sm">
				我的错题
			</view>
			<view v-for="(item,index) in errorsDataList" class="padding-sm border-bottom rowsb align-center">
				<view>
					{{item.title}}
				</view>
				<view @click="ErrosMen(item.id)">
					<image src="../../../static/shanchu.png" mode="widthFix" style="width: 40rpx;height: 40rpx;"></image>
				</view>
			</view>
		</view>
		<view v-if="errorsDataList==''" class="text-center padding text-gray text-sm">
				暂无更多内容
		</view>
	</view>
</template>

<script>
	const app = getApp().globalData
	import {
		errorsList,
		deleteErrors
	} from '../../../common/path.js'
	export default {
		data() {
			return {
				errorsDataList: [],
				optionid: 1
			}
		},
		onLoad(option) {
			if (option.id) {
				this.optionid = option.id
			}
			this.errorsList()

		},
		methods: {
			//查询错题
			errorsList() {
				let data = {
					uid: app.userInfo.id,
					type: this.optionid //1科目1 2 科目4
				}
				this.$axios.axios("POST", errorsList, data)
					.then(res => {
						console.log('回答错的===>', res.data)
						let errorsDataList = res.data
						// let setdataarr = Array.from(new Set(errorsDataList))
						// console.log('错题',setdataarr);
						this.errorsDataList = errorsDataList
					})
					.catch(err => {
						console.log(err)
					})
			},
			// 删除错题
			ErrosMen(id) {
				let that = this
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除该错题吗？',
					success: function(Res) {
						if (Res.confirm) {
							that.deleteErros(id)
						} else if (Res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},

			deleteErros(id) {
				let data = {
					id: id
				}
				this.$axios.axios("POST", deleteErrors, data)
					.then(res => {
						console.log('回答错的===>', res.msg)
						this.errorsList()
						this.$tools.showToast(res.msg)
					})
					.catch(err => {
						console.log(err)
					})
			}
		}
	}
</script>

<style>
</style>
